<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>轮播图</title>
    <style type="text/css">

        /*标题样式*/
        p{
            text-align: center;
            font-size: 30px;
            color: rgb(38, 54, 140);
            font-family: fantasy;

        }

    

        .imgBox{
            
            width: 90%;
            height: 600px;
            margin: 0 auto;

        }

        .imgBox img{
            width: 80%;
            height: 500px;
            margin: 0 auto;
            padding-top: 30px;

        }

        .img1{
            display: block;
        }

        .img2{
            display: none;
        }

        .img3{
            display: none;
        }

        .img4{
            display: none;
        }

        .img5{
            display: none;
        }


    </style>
</head>
<body>
<p>图片轮播展示</p>
<div class="imgBox">
    <img class="img-slide img1" src="image/3.jpg" alt="1">
    <img class="img-slide img2" src="image/4.jpeg" alt="2">
    <img class="img-slide img3" src="image/5.jpg" alt="3">
    <img class="img-slide img3" src="image/6.jpeg" alt="4">
    <img class="img-slide img3" src="image/7.jpeg" alt="5">
    
</div>
</body>



<script type="text/javascript">
    var index=0;
    //改变图片  逻辑控制函数
    function ChangeImg() {
        index++;
        var a=document.getElementsByClassName("img-slide");
        if(index>=a.length) index=0;    // 防止数组溢出

        for(var i=0;i<a.length;i++){    // 遍历每一个元素
            a[i].style.display='none';
        }
        a[index].style.display='block';    // 每次显示一张图片
    }
    //设置定时器，每隔两秒切换一张图片
    setInterval(ChangeImg,2000);
</script>


</html>

